/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package app.net.client;

import app.game.GlobalStatics;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * connect to server and initialize threads
 *
 * @author skyr
 */
public class ClientApp {
    
    //default ip
    public static String serverName = "127.0.0.1";
    
    public void init(int port, String serverName){
        try {
            // connecting to server
            System.out.println("Establishing connection. Please wait ...");
            Socket socket = new Socket(serverName, port);
            System.out.println("Connected: " + socket);
            
            // initialize game loop thread
            ClientGameLoop clientGameLoop = new ClientGameLoop(socket);
            clientGameLoop.start();
            
            // initialize thread tha receives from input from server
            ClientReceiveThread clientReceiveThread = new ClientReceiveThread(socket, clientGameLoop);
            clientReceiveThread.start();

        } catch (Exception ex) {
            Logger.getLogger(ClientApp.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void main(String[] args) {
        ClientApp app = new ClientApp();
        app.init(GlobalStatics.port, serverName);
    }
}
